The followinf files are to be edited with the corresponding .py files in the drive to allow tensorflow 2.1 work well.

--Original model was trained with tensorflow 1.13

callbacks.py, model.py and utils.py file

/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/keras/callbacks.py #> line 1532

/content/Mask_RCNN/mrcnn/utils.py

/content/Mask_RCNN/mrcnn/model.py

Set up logging and pre-trained model paths

This will default to sub-directories in your mask_rcnn_dir, but if you want them somewhere else, updated it here.

It will also download the pre-trained coco model.

Configuration

Define configurations for training on the Food dataset.

Note

These are settings that worked on my machine (GTX 970 graphics card). If you are getting OOM (Out of Memory) errors, you may need to tweak the settings or your computer may not be powerful enough. If you have a better graphics card, you will want to tweak it to take advantage of that.

Define the dataset

I've attempted to make this generic to any COCO-like dataset. That means if you have another dataset defined in the COCO format, it should work.

Create the Training and Validation Datasets

Make sure you download the training dataset linked at the top of this notebook. If you put the dataset somewhere else, update the paths below.

Display a few images from the training dataset

Create the Training Model and Train

This code is largely borrowed from the train_shapes.ipynb notebook.

Training

Train in two stages:

  1. Only the heads. Here we're freezing all the backbone layers and training only the randomly initialized layers (i.e. the ones that we didn't use pre-trained weights from MS COCO). To train only the head layers, pass layers='heads' to the train() function.

  2. Fine-tune all layers. For this simple example it's not necessary, but we're including it to show the process. Simply pass layers="all to train all layers.

Prepare to run Inference

Create a new InferenceConfig, then use it to create a new model.

Run Inference

Run model.detect() on real images.

We get some false positives, and some misses. More training images are likely needed to improve the results.